package com.hackerrank.challenges.finddigits;

import java.util.Scanner;

public class Solution {
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int T = in.nextInt();
		for(int t = 0; t < T; t++) {
			int N = in.nextInt(), R = N, c = 0;
			while(R > 0) {
				int d = R % 10;
				if(d > 0 && N % d == 0)
					c++;
				R /= 10;
			}
			System.out.println(c);
		}
	}
}
